package com.itheima.controller;

import com.alibaba.fastjson.JSON;
import com.itheima.entity.Result;
import com.itheima.service.BlogSortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/sort")
public class SortController {
    @Autowired
    private BlogSortService blogSortService;

    /**
     * 通过月份获取文章
     * @param monthDate
     * @return
     */
    @GetMapping("/getArticleByMonth")
    public String getArticleByMonth(@RequestParam("monthDate") String monthDate){
        List<String> contents = blogSortService.getArticleByMonth(monthDate);
       return JSON.toJSONString(new Result<>("success",contents));
    }

    /**
     * 归档:查所有月份
     * @return
     */
    @GetMapping("/getSortList")
    public String getSortList(){
        List<String> months = blogSortService.getSortList();
        return JSON.toJSONString(new Result<>("success",months));
    }
}
